<?php

class Core_Model_Media_Collection_Video extends Dcmp_Model_Collection_Strong {

    public function __construct() {
        parent::__construct();
        $this->setItemClass('media/video');
        $this->from('{t}media_video', 'a')
                ->select()->field('a.*');
    }

    public function filterBy($name, $arg) {
        switch ($name) {
            case 'status':
                $this->eq('a.status', ':status:s')->addParameter('status', $arg);
                break;
            case 'name':
                $this->like('a.name', ':name:s')->addParameter('name', "%$arg%");
                break;
            case 'mender':
                $this->like('mender_name', ':mender_name:s')->addParameter('mender_name', "%$arg%");
                break;
            case 'ids':
                $this->contain('a.id', ':ids:s')->addParameter('ids', $arg);
                break;
        }
        return parent::filterBy($name, $arg);
    }

    public function joinAccount() {
        $this->join()->inner('{t}permission_account', 'b')->on('a.mender_id', 'b.id')
                ->closest()
                ->select()->field('b.full_name', 'mender_name');
        return $this;
    }
}